#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;


int maxProduct(int num[], int size)
{
    int minSoFar = num[0], maxSoFar = num[0];
    int maxP = 0;
    for (int i = 1; i < size; i++) {
        int tmp = minSoFar;
	minSoFar = min(minSoFar*num[i], maxSoFar*num[i]);
        if (minSoFar == 0) minSoFar = 1;
        maxSoFar = max(tmp*num[i], maxSoFar*num[i]);
        if (maxSoFar == 0) maxSoFar = 1;
        maxP = max(maxSoFar, maxP);
    } 
    return maxP;
}


int main(int argc, char **argv)
{
    int num1[] = {6, -3, -10, 0, 2};
    cout << maxProduct(num1, sizeof(num1)/sizeof(int)) << endl;


    int num2[] = {-1, -3, -10, 0, 60};
    cout << maxProduct(num2, sizeof(num2)/sizeof(int)) << endl;

    int num3[] = {-2, -3, 0, -2, -40};
    cout << maxProduct(num3, sizeof(num3)/sizeof(int)) << endl;
}
